/**
 *    Copyright (c) [2021] [白晓明]
 *    [IMHarmonyOSLib] is licensed under Mulan PSL v2.
 *    You can use this software according to the terms and conditions of the Mulan PSL v2.
 *    You may obtain a copy of Mulan PSL v2 at:
 *             http://license.coscl.org.cn/MulanPSL2
 *    THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 *    See the Mulan PSL v2 for more details.
 */
package com.itming.ui.uilib.login;

import com.itming.ui.coptlib.core.IMIcon;
import com.itming.ui.uilib.ResourceTable;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.app.Context;

public class IMCustomLogin extends DirectionalLayout {
    public IMCustomLogin(Context context) {
        this(context, null);
    }

    public IMCustomLogin(Context context, AttrSet attrSet) {
        this(context, attrSet, null);
    }

    public IMCustomLogin(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        initImCustomLogin(context, attrSet);
    }

    private void initImCustomLogin(Context context, AttrSet attrSet) {
        //动态加载Layout
        Component component = LayoutScatter.getInstance(context)
                .parse(ResourceTable.Layout_layout_login, null, false);

        //子组件
        IMIcon imIcon = (IMIcon) component.findComponentById(ResourceTable.Id_close);

        addComponent(component);

        if (attrSet.getAttr("visible_close").isPresent()) {
            if (attrSet.getAttr("visible_close").get().getBoolValue()) {
                imIcon.setVisibility(VISIBLE);
            } else {
                imIcon.setVisibility(HIDE);
            }
        } else {
            imIcon.setVisibility(HIDE);
        }
    }
}
